package inf.coach.mobile;

import java.math.*;
public class Distance {
	
	static double lat1;
	static double lon1;
	static double lat2;
	static double lon2;
    private final static double EARTH_RADIUS = 6378137.0;  
	public static double getDistance (poigeo p1,poigeo p2)
	{

		lat1=p1.lat;
		lon1=p1.lon;
		lat2=p2.lat;
		lon2=p2.lon;
		
		       double radLat1 = (lat1 * Math.PI / 180.0);
		       double radLat2 = (lat2 * Math.PI / 180.0);
		       double a = radLat1 - radLat2;
		       double b = (lon1 - lon2) * Math.PI / 180.0;
		       double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
		              + Math.cos(radLat1) * Math.cos(radLat2)
		              * Math.pow(Math.sin(b / 2), 2)));
		       s = s * EARTH_RADIUS;
		       s = Math.round(s * 10000) / 10000;
		       return s;	
	}
}
